package gatperdut.chato.core.characters;

import gatperdut.chato.constants.CSConstantsCommandResult.CommandExecutionResult;
import gatperdut.chato.core.ChatoServer;
import gatperdut.chato.core.interpreter.BotInterpreter;
import gatperdut.chato.model.Chato.Entity.NPC;

public class BotController extends BaseController {

    public BotController( ChatoServer chatoServer, NPC npc ) {
        super( chatoServer );

        setCharacter( npc );

        setRoomController( chatoServer.getRoomHandler().getRoomToController().get( getCharacter().getRoom() ) );
        getRoomController().getCharactersController().enterRoom( this );
    }

    @Override
    public void doRun() {
        while ( true ) {
            try {
                Thread.sleep( 23000 );
            }
            catch ( InterruptedException e ) {
                return;
            }
            CommandExecutionResult cer = getInterpreter().exec( "(waves amiably)" );
            if ( cer == CommandExecutionResult.QUIT_LOGOUT ) {
                break;
            }
        }
    }

    @Override
    public void die( BaseController killer ) {
        super.die( killer );
        getChatoServer().getEntityHandler().removeNpc( (NPC) this.getCharacter() );
        interrupt();
    }

    @Override
    public void tx( String message ) {
        // TODO Auto-generated method stub

    }

    @Override
    public String rx() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public BotInterpreter getInterpreter() {
        return (BotInterpreter) super.getInterpreter();
    }

    @Override
    public String whoAmI() {
        // TODO
        return "some random bot.";
    }

}
